#region License, Terms and Author(s)
//
// Schnell - Wiki widgets
// Copyright (c) 2007 Atif Aziz. All rights reserved.
//
//  Author(s):
//      Atif Aziz, http://www.raboof.com
//
// This library is free software; you can redistribute it and/or modify it 
// under the terms of the GNU Lesser General Public License as published by 
// the Free Software Foundation; either version 2.1 of the License, or (at 
// your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, 
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
//
#endregion

namespace WikiPad
{
    #region Imports

    using System;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.IO;

    #endregion

    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        
        [ STAThread ]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            MainForm form = new MainForm();
            form.Show();

            if (args.Length > 0)
                form.OpenFile(args[0]);

            Application.Run(form);
        }

        internal static void ShowExceptionDialog(Exception e)
        {
            ShowExceptionDialog(e, null);
        }

        internal static void ShowExceptionDialog(Exception e, string title)
        {
            ShowExceptionDialog(e, title, null);
        }

        internal static void ShowExceptionDialog(Exception e, string title, IWin32Window owner)
        {
            Debug.Assert(e != null);

            Trace.WriteLine(e.ToString());

            if (!SystemInformation.UserInteractive)
                return;

            StringWriter message = new StringWriter();
            message.WriteLine(e.GetBaseException().Message);

#if DEBUG

            message.WriteLine();
            message.WriteLine(e.ToString());

#endif

            MessageBox.Show(owner, message.ToString(),
                Mask.EmptyString(title, Application.ProductName),
                MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}